package com.eeprint.web.controller.terminal;

import com.eeprint.common.utils.AjaxResult;
import com.eeprint.system.domain.terminal.vo.TerminalPrintJobData;
import com.eeprint.system.service.terminal.impl.TerminalServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigInteger;
import java.util.List;
import java.util.Map;

/**
 * Description
 *
 * @author Samven7
 * @date 2020/10/18 11:10
 */
@RestController
public class TerminalPrintJobController {

    @Autowired
    TerminalServiceImpl terminalService;

    /**
     * 打印记录列表
     *
     * @param tenantTerminalCode 终端登陆码
     * @return AjaxResult
     */
    @GetMapping("/terminal/list")
    public AjaxResult list(@RequestBody Map<String, Object> map) {
        String code = (String) map.get("tenantTerminalCode");
        List<TerminalPrintJobData> allPrintJob = terminalService.getAllPrintJobByTerminalCode(code);
        // System.out.println(allPrintJob);
        if(allPrintJob != null){
            return AjaxResult.success(allPrintJob);
        }else {
            return AjaxResult.error("获取失败");
        }
    }

    /**
     * 打印记录移除
     *
     * @param id 作业编号
     * @return AjaxResult
     */
    @PostMapping("/terminal/remove")
    public AjaxResult removePrintJob(@RequestBody BigInteger id) {
        if (terminalService.removePrintJob(id)) {
            return AjaxResult.success();
        } else {
            return AjaxResult.error();
        }
    }

    /**
     * 打印记录重打
     *
     * @param id 作业编号
     * @return AjaxResult
     */
    @PostMapping("/terminal/again")
    public AjaxResult againPrintJob(@RequestBody BigInteger id) {
        if (terminalService.ReprintPrintJob(id)) {
            return AjaxResult.success();
        } else {
            return AjaxResult.error();
        }
    }

    /**
     * 打印记录续打
     *
     * @param id 作业编号
     * @return AjaxResult
     */
    @PostMapping("/terminal/continue")
    public AjaxResult continuePrintJob(@RequestBody BigInteger id) {
        if (terminalService.continuePrintJob(id)) {
            return AjaxResult.success();
        } else {
            return AjaxResult.error();
        }
    }


}
